import java.util.*;

public class 子集 {
    //https://leetcode.cn/problems/subsets/description/
    //全局变量来做这道题, 需要注意回溯
    public static List<List<Integer>> ret;
    public static List<Integer> path;
    public static int n;
    public List<List<Integer>> subsets(int[] nums) {
        n = nums.length;
        ret = new ArrayList<>();
        path = new ArrayList<>();
        dfs(0,nums);
        return ret;
    }

    public void dfs(int pos,int[] nums) {
        if(pos == n){
            List<Integer> cur = new ArrayList<>(path);
            ret.add(cur);
            return;
        }
        //选或不选
        path.add(nums[pos]);
        dfs(pos + 1,nums);
        //回溯
        path.remove(path.size() - 1);
        dfs(pos + 1,nums);
    }
}
